package coroutines.launch

import kotlinx.coroutines.async
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import java.text.SimpleDateFormat
import java.util.*

class CoroutineAwaitTest {
}

fun main() {
    runBlocking {
        launch {
            val df = SimpleDateFormat("yyyy-MM-dd HH:mm:ss") //设置日期格式

            println("${df.format(Date())} async start")

            val result0 = async { multi(4) }
            val result1 = async { multi(5) }

            println("${df.format(Date())} async executed")

            val value0 = result0.await()
            val value1 = result1.await()

            println("${df.format(Date())} async await()")

            println("${df.format(Date())} async end result0 = ${value0}, result1 = $value1")
        }
    }
}
//
//suspend fun multi(num: Int): Int {
//    delay(num * 1000L)
//
//    return num * num
//}